<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        position: relative;
        height: 100px;
        width: 100px;
        background-color: yellow;
        left: 0;
        top: 0;
      }
    </style>
  </head>
  <body>
    <div></div>
    <!-- 作业：1.复习 2. 通过promise实现方块的运动 。3.手写一个promisify -->
    <script>
      let box = document.querySelector("div");

      new Promise((resolve, reject) => {
        box.style.left = "8px";
        var t1 = setInterval(() => {
          // 设置步长
          var step = 5;

          box.style.left = box.offsetLeft + step + "px";
          if (box.style.left == "500px") {
            clearInterval(t1);
          }
        }, 100);
      });
      //   .then((res) => {
      //     setTimeout(() => {
      //       box.style.top = "200px";
      //     }, 600);
      //   })
      //   .then((res) => {
      //     setTimeout(() => {
      //       box.style.left = "0px";
      //     }, 900);
      //   })
      //   .then((res) => {
      //     setTimeout(() => {
      //       box.style.top = "0px";
      //     }, 1200);
      //   });
    </script>
  </body>
</html>
